package com.niii.statistics.service;


import com.niii.statistics.mapper.ProvincialgdpMapper;
import com.niii.statistics.mapper.ProvincialpopMapper;
import com.niii.statistics.pojo.Provincialgdp;
import com.niii.statistics.pojo.ProvincialgdpExample;
import com.niii.statistics.pojo.Provincialpop;
import com.niii.statistics.pojo.ProvincialpopExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class ProvincialgdpService {

    @Autowired
    private ProvincialgdpMapper provincialgdpMapper;

    @Autowired
    private ProvincialpopMapper provincialpopMapper;

    public Map<String, List> getAll(){
        Map<String, List> res = new HashMap<>();
        List<Provincialgdp> list = provincialgdpMapper.selectByExample(new ProvincialgdpExample());
        List<Double> first =list.stream().map(Provincialgdp::getFirst).collect(Collectors.toList());
        List<Double> second =list.stream().map(Provincialgdp::getSecond).collect(Collectors.toList());
        List<Double> third =list.stream().map(Provincialgdp::getThird).collect(Collectors.toList());
        List<Double> total =list.stream().map(Provincialgdp::getTotal).collect(Collectors.toList());
        List<Double> perCapita =list.stream().map(Provincialgdp::getPerCapita).collect(Collectors.toList());
        List<String> year =list.stream().map(Provincialgdp::getYear).collect(Collectors.toList());

        res.put("first",first);
        res.put("second",second);
        res.put("third",third);
        res.put("total",total);
        res.put("perCapita",perCapita);
        res.put("year",year);

        return res;
    }

    public Map<String, List> getProvincial(String provincialName){
        Map<String, List> res = new HashMap<>();
        ProvincialgdpExample provincialgdpExample = new ProvincialgdpExample();
        provincialgdpExample.createCriteria().andProvincialNameEqualTo(provincialName);
        List<Provincialgdp> list = provincialgdpMapper.selectByExample(provincialgdpExample);
        List<Double> first =list.stream().map(Provincialgdp::getFirst).collect(Collectors.toList());
        List<Double> second =list.stream().map(Provincialgdp::getSecond).collect(Collectors.toList());
        List<Double> third =list.stream().map(Provincialgdp::getThird).collect(Collectors.toList());
        List<Double> total =list.stream().map(Provincialgdp::getTotal).collect(Collectors.toList());
        List<Double> perCapita =list.stream().map(Provincialgdp::getPerCapita).collect(Collectors.toList());
        List<String> year =list.stream().map(Provincialgdp::getYear).collect(Collectors.toList());

        res.put("first",first);
        res.put("second",second);
        res.put("third",third);
        res.put("total",total);
        res.put("perCapita",perCapita);
        res.put("year",year);

        return res;
    }


    public Map<String, List> getProvincialPop(String provincialName){
        Map<String, List> res = new HashMap<>();
        ProvincialpopExample provincialpopExample = new ProvincialpopExample();
        provincialpopExample.createCriteria().andProvincialNameEqualTo(provincialName);
        List<Provincialpop> list = provincialpopMapper.selectByExample(provincialpopExample);
        List<Double> male =list.stream().map(Provincialpop::getMale).collect(Collectors.toList());
//        List<Double> second =list.stream().map(Provincialgdp::getSecond).collect(Collectors.toList());
//        List<Double> third =list.stream().map(Provincialgdp::getThird).collect(Collectors.toList());
//        List<Double> total =list.stream().map(Provincialgdp::getTotal).collect(Collectors.toList());
//        List<Double> perCapita =list.stream().map(Provincialgdp::getPerCapita).collect(Collectors.toList());
        List<Double> female =list.stream().map(Provincialpop::getFemale).collect(Collectors.toList());
        List<Double> total =list.stream().map(Provincialpop::getTotal).collect(Collectors.toList());
        List<String> year =list.stream().map(Provincialpop::getYear).collect(Collectors.toList());

        res.put("male",male);
        res.put("female",female);
        res.put("total",total);
        res.put("year",year);


        return res;
    }



}
